let iframe = document.querySelector('iframe');
const jumpUrl = (_url) => {
    iframe.src = `./${_url}`
    sessionStorage.setItem(`current_page`, `./${_url}`)
}


const init_home = () => {
    let userinfo = localStorage.getItem('userinfo')
    if (userinfo) {
        userinfo = JSON.parse(userinfo)
        document.querySelector('.username').innerHTML = userinfo.username
        document.querySelector('.email').innerHTML = userinfo.email ? userinfo.email : '暂无邮箱'
        let current_page = sessionStorage.getItem('current_page')
        if (current_page) iframe.src = current_page
        else {
            iframe.src = './users.html'
        }
    } else {
        alert('当前未登录，请登录后再访问系统')
        location.href = '../login.html'
    }
}

//退出登录
const out = () => {
    localStorage.removeItem('userinfo')
    location.href = './login.html'
}

window.onload = function() {
    init_home()
}